<template>
    <div>
      <h1>分页显示</h1>
      价格<input type="text" v-model="page.pmin">-<input type="text" v-model="page.pmax">
    名称<input type="text" v-model="page.names">
    <input type="button" value="查询" @click="cha">
    <input type="button" value="根据id升序" @click="orrder('asc')">
    <input type="button" value="根据id降序" @click="orrder('desc')">

      <table>
        <thead>
            <tr>
                <td>名称</td>
                <td>图片</td>
                <td>时间</td>
                <td>状态</td>
                <td>价格</td>
                <td>类型</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="m in data">
                <td>{{m.hname}}</td>
                <td> <img style="height: 100px;width: 100px;" :src="'https://localhost:7041'+m.himg"></td>
                <td>{{m.htime}}</td>
                <td>{{m.sates}}</td>
                <td>{{m.hprice}}</td>
                <td>{{m.typeid}}</td>
                <td> <input type="button" value="编辑" @click="Enid(m.hid)">
                <a :href="'https://localhost:7041'+m.himg" target="_blank">点击看图</a>
                </td>
            </tr>
        </tbody>
      </table>
    </div>
    <input type="button" value="首页" @click="Fanye(1)">
    <input type="button" value="上一页" @click="Fanye(2)">
    <input type="button" value="下一页" @click="Fanye(3)">
    <input type="button" value="尾页" @click="Fanye(4)">
    一共{{paga.pcount}}页，一共{{paga.count}}行，每页{{page.size}}行，当前第{{page.index}}页
    <select v-model="page.size" @change="rong">
        <option>3</option>
        <option>4</option>
        <option>5</option>
    </select>
    <input type="text" v-model="page.index">
    <input type="button" value="跳转" @click="tiao">
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';
var router=useRouter();

const Enid=(vid:any)=>
{
router.push({path:"/Enid",query:{id:vid}})
}

const tiao=()=>
{
    if(page.value.index>=1&&page.value.index<=paga.value.pcount)
{
    Getdata();
}
}

const orrder=(val:any)=>
{
page.value.desc=val;
Getdata();
}

const cha=()=>
{
    page.value.index=1;
    Getdata();
}

const rong=()=>
{
    page.value.index=1;
    Getdata();
}

onMounted(()=>
{
    
    Getdata();
})

const Fanye=(vid:any)=>
{
    if(vid==1)
{
page.value.index=1;
Getdata();
}

if(vid==2)
{
    if(page.value.index>1)
{
    page.value.index-=1;
Getdata();
}
}
if(vid==3)
{
    if(page.value.index<paga.value.pcount)
{
    page.value.index+=1;
Getdata();
}
}

if(vid==4)
{
page.value.index=paga.value.pcount;
Getdata();
}




}

const data=ref([{
    "hid": 0,
  "hname": "",
  "himg": "",
  "htime": "",
  "sates": true,
  "hprice": 0,
  "typeid": 0
}])

const paga=ref({
    count:0,
    pcount:3
})

const page=ref({
index:1,
size:3,    
pmin:"",
pmax:"",
names:"",
desc:"asc"

})

const Getdata=()=>
{
    axios.get("https://localhost:7041/api/hotel/GetAlly",{params:page.value}).then(res=>
        {
            data.value=res.data.data;
            paga.value.count=res.data.count;
            paga.value.pcount=Math.ceil(paga.value.count/page.value.size);
        }
    )
}




</script>

<style scoped>

</style>